﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;
using PowerCreator.LMS.Web.Task;
using PowerCreator.LMS.Task.Entity;

public partial class Theme_3_TaskCommentList : PowerCreator.LMS.Web.Base.WebBasePage
{
    public string _contentID = "0";
    public string rqResourceID = "0";
    public string StrEvaluation = "";
    public string StrDivID = "";
    //PowerCreator.LMS.Web.Grade.GradeManager op = new PowerCreator.LMS.Web.Grade.GradeManager();
    PowerCreator.LMS.Web.User.User opuser = new PowerCreator.LMS.Web.User.User();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    TaskManag objTaskManag = new TaskManag();
    TaskCommentManag objTaskCommentManag = new TaskCommentManag();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["TaskID"] != null && Request.Params["TaskID"].Trim() != "")
        {
            int TaskID = int.Parse(Request.Params["TaskID"].ToString());
            ViewState["TaskID"] = TaskID;

        }
        if (Request.Params["TaskClassID"] != null && Request.Params["TaskClassID"].Trim() != "")
        {
            int TaskClassID = int.Parse(Request.Params["TaskClassID"].ToString());
            ViewState["TaskClassID"] = TaskClassID;

        }
        if (Request.Params["TaskUserID"] != null && Request.Params["TaskUserID"].Trim() != "")
        {
            int TaskUserID = int.Parse(Request.Params["TaskUserID"].ToString());
            ViewState["TaskUserID"] = TaskUserID;

        }
        if (Request.Params["ResourceID"] != null && Request.Params["ResourceID"].Trim() != "")
        {
            int ResourceID = int.Parse(Request.Params["ResourceID"].ToString());
            ViewState["ResourceID"] = ResourceID;

        }

        if (Request.Params["ResourceID"] != null)
        {
            rqResourceID = Request.Params["ResourceID"];
        }
        if (Request.Params["ContentID"] != null)
        {
            _contentID = Request.Params["ContentID"].ToString();
        }


        string search = GetSearch();
        BinderPager(search);
        BinderRPT(search, 1);
        //StrEvaluation = GetEvaluation(rqResourceID);
    }

    private string GetSearch()
    {
         string searchTaskComment=string.Empty;
        if (rqResourceID != "0")
            searchTaskComment = string.Format(" TaskCtRangeType=0 and  TaskCtTaskID={0} and TaskCtTaskClassID={1} and TaskCtUserID={2} and TaskCtType=0 ", ViewState["TaskID"].ToString(), ViewState["TaskClassID"].ToString(), ViewState["TaskUserID"].ToString());
        if (_contentID != "0")
            searchTaskComment = string.Format(" TaskCtRangeType=0 and  FKTaskCtResourceGuid='{0}'", _contentID);


        

        return searchTaskComment;
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objTaskCommentManag.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }
    private void BinderRPT(string search, int pageIndex)
    {
        string Rt = "";
        DataTable dt = objTaskCommentManag.Query(search, " TaskCtCreateTime desc", 5, pageIndex);
        dt.Columns.Add("FormatGradeAsfTime");
        dt.Columns.Add("FKGradeUserName");
        dt.Columns.Add("GradeContent_Short");
        if (rqResourceID != "0")
        {
          
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    dt.Rows[i]["FormatGradeAsfTime"] = PowerCreator.LMS.Common.Utils.TimeUtils.FormatTime(dt.Rows[i]["TaskCtVideoTime"].ToString());
                    dt.Rows[i]["FKGradeUserName"] = opuser.GetRealNameByUserID(int.Parse(dt.Rows[i]["FKTaskCtCreateID"].ToString()));


                    string Position = dt.Rows[i]["TaskCtVideoTime"].ToString();
                    StrDivID = StrDivID + Position + ",";
                    Rt = Rt + "<div id=\"" + Position + "\"  style=\"display: none;\">" + dt.Rows[i]["FormatGradeAsfTime"].ToString() + "&nbsp;&nbsp;";
                    Rt = Rt + dt.Rows[i]["TaskCtContent"].ToString();
                    Rt = Rt + "[" + dt.Rows[i]["FKGradeUserName"].ToString() + config.GetLanagerValueByKey("theme_Theme_AddTo", PowerCreator.LMS.Language.LanagetItemType.Page);
                    Rt = Rt + dt.Rows[i]["TaskCtCreateTime"].ToString() + "]</div>";

                    dt.Rows[i]["GradeContent_Short"] = PowerCreator.LMS.Common.Utils.StringUtils.Left(dt.Rows[i]["TaskCtContent"].ToString(), 19);
                }
                if (StrDivID.Length > 0)
                    StrDivID = StrDivID.Substring(0, StrDivID.Length - 1);
            }
        }
        if (_contentID != "0")
        {

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //dt.Rows[i]["FormatGradeAsfTime"] = PowerCreator.LMS.Common.Utils.TimeUtils.FormatTime(dt.Rows[i]["GradeAsfTime"].ToString());
                dt.Rows[i]["FKGradeUserName"] = opuser.GetRealNameByUserID(int.Parse(dt.Rows[i]["FKTaskCtCreateID"].ToString()));
                dt.Rows[i]["GradeContent_Short"] = PowerCreator.LMS.Common.Utils.StringUtils.Left(dt.Rows[i]["TaskCtContent"].ToString(), 12);
            }

        }
        lblCommentCount.Text = AspNetPager1.RecordCount.ToString();

        rptCommentList.DataSource = dt;
        rptCommentList.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
    private string GetEvaluation(string ResouurceID)
    {
        string Rt = "";
        //string sql = "";

        string searchTaskComment = string.Empty;
        if (rqResourceID != "0")
            searchTaskComment = string.Format(" TaskCtRangeType=0 and  TaskCtTaskID={0} and TaskCtTaskClassID={1} and TaskCtUserID={2} and TaskCtType=0 ", ViewState["TaskID"].ToString(), ViewState["TaskClassID"].ToString(), ViewState["TaskUserID"].ToString());
        if (_contentID != "0")
            searchTaskComment = string.Format(" TaskCtRangeType=0 and  FKTaskCtResourceGuid='{0}'", _contentID);

        string orderby = " TaskCtCreateTime desc";
        int count = 0;
        count = objTaskManag.Count(searchTaskComment);
        DataTable dt = objTaskManag.Query(searchTaskComment, orderby, count, 1);
        dt.Columns.Add("FormatGradeAsfTime");
        dt.Columns.Add("FKGradeUserName");

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["FormatGradeAsfTime"] = PowerCreator.LMS.Common.Utils.TimeUtils.FormatTime(dt.Rows[i]["TaskCtVideoTime"].ToString());
                dt.Rows[i]["FKGradeUserName"] = opuser.GetRealNameByUserID(int.Parse(dt.Rows[i]["FKTaskCtCreateID"].ToString()));


                string Position = dt.Rows[i]["TaskCtVideoTime"].ToString();
                StrDivID = StrDivID + Position + ",";
                Rt = Rt + "<div id=\"" + Position + "\"  style=\"display: none;\">" + dt.Rows[i]["FormatGradeAsfTime"].ToString() + "&nbsp;&nbsp;";
                Rt = Rt + dt.Rows[i]["GradeContent"].ToString();
                Rt = Rt + "[" + dt.Rows[i]["FKGradeUserName"].ToString() + config.GetLanagerValueByKey("theme_Theme_AddTo", PowerCreator.LMS.Language.LanagetItemType.Page);
                Rt = Rt + dt.Rows[i]["TaskCtCreateTime"].ToString() + "]</div>";
            }
            if (StrDivID.Length > 0)
                StrDivID = StrDivID.Substring(0, StrDivID.Length - 1);
        }


        return Rt;
    }
    protected void rptCommentList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderRPT(search, 1);
    }
}

